﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DevilshMath
{
    class EquationObject
    {
        public int LeftValue;
        public int RightValue;
        public int UserSolution;
        public char Operator;

        public int CalculatedSolution {
          get{
            if (Operator.Equals("-")) {
              return (LeftValue - RightValue);
            } else {
              return (LeftValue + RightValue);
            };
          }
        }

        private void SetLandR(ref Random aRandom){
          LeftValue = aRandom.Next(35);
          RightValue = aRandom.Next(35);

          if (Operator.Equals("-") && LeftValue <= RightValue) {
            SetLandR(ref aRandom);
            return;
          }
                               
        } 

        private char GetRandomOperator(ref string aOperatorString, ref Random aRandom){          
          return aOperatorString[aRandom.Next(int.MaxValue) % aOperatorString.Length];
        }

        private void SetParts() {
          Random zRnd = new Random();
          Operator = GetRandomOperator(ref CONSTANTS.OPERATORS_EASY, ref zRnd);
          SetLandR(ref zRnd);
        }

        // constructor
        public EquationObject(){
          SetParts();
        }

        // destructor
        ~EquationObject();

        public bool isCorrect {
          get { 
            return UserSolution.Equals(CalculatedSolution);
          }            
        }
        
    }
}
